/*
 * 保存菜品
 * 2018-03-23
 */
;(function ($) {
	//保存菜品入口
	$.fn.alertModal=function(options){
    	//创建对象
		var $ele = new alertModal(this, options);
		//入口
		$ele.judge()
	}
	
	//构造函数
    var alertModal = function(ele, opt) {   	
    	//选择器对象    	
        this.$element=ele;   
        //默认参数
        this.defaults = {
        	data:"",
        	getDefaultBack:function(){},
        	getCancel:function(){},
        },       
        //初始化参数
        this.options = $.extend({}, this.defaults, opt);
    }

    //属性方法
    alertModal.prototype = {
		judge:function(){
			var $t=this;
    		var $opt=$t.options;
			if($opt.data.RETURN==-10){//checkbox提示
				$t.initHtml();
			}else{
				$t.loadOption();
			}
		},
		initHtml:function(){
			var $t=this;
    		var $opt=$t.options;
//    		$t.$element.addClass("modal").attr("tabindex","-2").attr("data-backdrop","static")
    		html='<div id="alertModal" class="modal fade">'+
	    			'<div class="modal-dialog" style="width:600px;">'+
						'<div class="modal-content">'+     
				  			'<div class="modal-header no-padding">'+
								'<div class="table-header">'+
//									'<button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-top:6px;">'+
//										'<span class="white">&times;</span>'+
//									'</button>'+
									$.i18n.propJsp("!提示")+
								'</div>'+
							'</div>	'+
							'<div class="modal-body" id="main_content">'+  
							'</div>'+
		  				'</div>'+
		  			'</div>'+		
	  			'</div>'+
	  			'</div>';
		
//			$t.$element.html(html);
    		$(".row").after(html)
			$t.getDefault()
		},
    	//获取默认值
    	getDefault:function(){
    		var $t=this;
    		var $opt=$t.options;
    		var data=$opt.data
    		
    		var arg={}
    		var MSG = data.MSG;
			var name = data.checkbox;
			var value = (data.checkboxvalue||"");
			
			var checked = "";
			if(value==1){
				checked = "checked"
			}
			
			var html = 	'<h3 class="header smaller lighter blue">'+
							'<i class="ace-icon fa fa-bullhorn"></i>'+$.i18n.propJsp("提示")+
						'</h3>'+
						'<div class="alert alert-block alert-danger">'+
							'<label>'+
								'<input id="checkin_cccheckbox" type="checkbox" name="'+name+'" value="" class="ace" '+checked+'/>'+
								'<span class="lbl" style="color:#478fca;display:inline-flex;align-items:center;">'+MSG+'</span>'+
							'</label>'+
						'</div>';
			$( "<style>input[type=checkbox].ace + .lbl::before, input[type=radio].ace + .lbl::before{ height: 30px; line-height:30px;min-width:30px;font-size:25px;margin-right:10px;}</style>" ).appendTo( "body" );
			bootbox.dialog({
				message: html,
				buttons: 			
				{
					"button1":{
						"label" : $.i18n.propJsp("确定"),
						"className" : "btn-large btn-info",
						"callback" : function(){
							if($("#checkin_cccheckbox").prop("checked")){
								arg[name]="yes";
								$opt.getDefaultBack(arg);
							}else{
								arg[name]="no";
								$opt.getDefaultBack(arg);
							}
						}
					},	
					"button" :
					{
						"label" : $.i18n.propJsp(" 取消 "),
						"className" : "btn-large",
						"callback" : function(){
							arg[name]="no";
							$opt.getDefaultBack(arg);
						}
					},
				}
			});
    		
		},
		loadOption:function(){
			var $t=this;
    		var $opt=$t.options;
			html='<div id="alertModal" class="modal fade">'+
						'<div class="modal-dialog" style="width:600px;">'+
							'<div class="modal-content">'+     
					  			'<div class="modal-header no-padding">'+
									'<div class="table-header">'+
//										'<button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-top:6px;">'+
//											'<span class="white">&times;</span>'+
//										'</button>'+
										$.i18n.propJsp("!提示")+
									'</div>'+
								'</div>	'+
								'<div class="modal-body" id="main_content">'+  
								'</div>'+
			  				'</div>'+
			  			'</div>'+		
						'</div>'+
						'</div>';
			
			//	$t.$element.html(html);
				$(".row").after(html)
				$t.bindClick()
		},
		bindClick:function(){
			var $t=this;
    		var $opt=$t.options;
			
			var html = 	'<h3 class="header smaller lighter blue">'+
							'<i class="ace-icon fa fa-bullhorn"></i>'+$opt.data.MSG+
						'</h3>'
			bootbox.dialog({
				message: html,
				buttons: 			
				{
					"button1":{
						"label" : $.i18n.propJsp("确定"),
						"className" : "btn-large btn-info",
						"callback" : function(){
							$opt.getDefaultBack()
						}
					},	
					"button" :
					{
						"label" : $.i18n.propJsp(" 取消 "),
						"className" : "btn-large",
						"callback" : function(){
							$opt.getCancel()
						}
					},
				}
			});
		},
		//返回筛选器对象,用于链式操作
    	hsOle: function() {
            return this.$element;      
        }
    }
})(jQuery);